package com.zhong.thesimpleconnection.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.os.FileObserver;
import android.support.v4.app.NotificationCompat;

import com.zhong.thesimpleconnection.R;

/**
 * Created by 俊峰 on 2017/5/18.
 * 用于监听MyCryptSecret文件夹的状态
 */

public class MyFileObserver extends FileObserver {
    private Context mContext;
    public MyFileObserver(String path) {
        super(path);
    }

    public MyFileObserver(String path, Context context){
        super(path);
        mContext = context;
    }

    @Override
    public void onEvent(int event, String path) {
        switch (event) {
            case FileObserver.DELETE:
            case FileObserver.ALL_EVENTS:
            case FileObserver.OPEN:
            case FileObserver.ATTRIB:
            case FileObserver.CLOSE_NOWRITE:
            case FileObserver.CLOSE_WRITE:
            case FileObserver.MODIFY:
            case FileObserver.MOVED_TO:
            case FileObserver.CREATE:
            case FileObserver.MOVE_SELF:
            case FileObserver.MOVED_FROM:
            case FileObserver.DELETE_SELF:
            case FileObserver.ACCESS:
                NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
                Notification notification = builder.setSmallIcon(R.mipmap.rpt)
                        .setContentTitle(mContext.getResources().getString(R.string.Dialog_Warn_Warn_Title))
                        .setContentText(mContext.getResources().getString(R.string.Notification_About_File))
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(mContext.getResources().getString(R.string.Notification_About_File_Big)))
                        .build();
                NotificationManager managerCompat = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
                managerCompat.notify(0, notification);
                break;
        }
    }
}
